<script type="text/javascript">
function show_this_meta(oValue) {
    hide_all_meta();
    if (oValue == 'page') {
        $('#page_meta').show();
        $('#select_template_tr').show();
        $('#select_url_tr').show();
    }
    if (oValue == 'list') {
        $('#customfields').show();
        $('#select_template_tr').show();
        $('#select_url_tr').show();
        $('#list_type_tr').show();
    }
    if (oValue == 'item') {
        $('#select_template_tr').show();
    }
    $('#select_template').html(get_templates_select(oValue));
}

function get_templates_select(oType) {
    page = '<?php echo $html->select('Diagram/template', get_templates_as_array('page'), array('id'=>'diagram_template')); ?>';
    list = '<?php echo $html->select('Diagram/template', get_templates_as_array('list'), array('id'=>'diagram_template')); ?>';
    if (oType == 'page') {
        return page;
    } else if (oType == 'list') {
        return list;
    }
}

function hide_all_meta() {
    $('#page_meta').hide();
    $('#customfields').hide();
    $('#select_template_tr').hide();
    $('#list_type_tr').hide();
}

function check_input() {
    oType = $("input[@type=radio][@checked]").val();
    if (!oType) {
        alert('请选择条目类型.');
        return false;
    }
    diagram_slug = $('#diagram_slug').val();
    if (diagram_slug == '') {
        alert('网址目录不能为空!');
        $('#diagram_slug').focus();
        return false;
    }
    return true;
}

var tr_count = <?php echo $tr_count; ?>;
function add_custom_row() {
    first_row = $('#custom_table_fist_tr');
    haha = first_row.html();

    first_row.after('<tr id="tr_' + tr_count + '"><td><input type="text" size="5" name="data[Fields][order][]" /></td><input type="text" size="20" name="data[Fields][title][]"/></td><td><input type="text" size="20" name="data[Fields][key][]"/></td><td><a href="#" onclick="delete_this_row(' + tr_count + '); return false"><?php __e('Delete'); ?></a></td></tr>');
    tr_count += 1;

}

function delete_this_row(tr_id) {
    $('#tr_' + tr_id).remove();
}

function use_input() {
    $('#use_input_description').hide();
    $('#select_template').hide();
    $('#custom_input').show();
    $('#is_custom_template').val('true');
}

function cancel_custom_input() {
    $('#custom_input').hide();
    $('#use_input_description').show();
    $('#select_template').show();
    $('#is_custom_template').val('');

}
</script>
<style type="text/css">
#select_template {
    display:inline;
    padding-right:10px;
}
</style>
<div id="sub-menu-box"><?php echo $html->admin_link(' &laquo; ' . __('Return Diagram Manage'), '/diagram_manage'); ?></div>
<div id="content">
<form id="post_form" name="post_form" method="post" action="" enctype="multipart/form-data" onsubmit="return check_input();">
<table width="100%">
  <tr>
    <td>
      <b><?php __e('Diagram type'); ?></b>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<?php echo $html->radio('Diagram/type', array('id'=>'page', 'value'=>'page', 'onclick'=>'show_this_meta(this.value);')); ?><label for="page"> <?php __e('Page'); ?></label>
<?php echo $html->radio('Diagram/type', array('id'=>'list', 'value'=>'list', 'onclick'=>'show_this_meta(this.value);')); ?><label for="list"> <?php __e('List'); ?></label>
<?php echo $html->radio('Diagram/type', array('id'=>'item', 'value'=>'item', 'onclick'=>'show_this_meta(this.value);')); ?><label for="item"> <?php __e('Item'); ?></label>
<?php echo $html->radio('Diagram/type', array('id'=>'url', 'value'=>'url', 'onclick'=>'show_this_meta(this.value);')); ?><label for="url"> <?php __e('Url link'); ?></label>
   
<div id="post_meta">
    <table>
      <tr class="finalrow">
        <th><?php __e('Parent'); ?></th>
        <td>
        <select name="data[Diagram][parent]" id="diagram_parent"  style="width:100%;">
        <?php echo $diagram_select_option_list; ?>
       </select>
        </td>
      </tr>
      <tr class="finalrow">
        <th><?php __e('Diagram title'); ?></th>
        <td><span class="errorbox-good">
            <?php echo $html->input('Diagram/title', array('style'=>'width:100%')); ?></span> </td>
      </tr>
      <tr class="finalrow" id="select_url_tr">
        <th><?php __e('Diagram url'); ?></th>
        <td><?php echo $html->input('Diagram/url', array('id'=>'diagram_url', 'style'=>'width:100%')); ?> </td>
      </tr>
      <tr class="finalrow" id="select_template_tr" style="<?php echo $templates_tr_style; ?>">
        <th><?php __e('Template'); ?></th>
        <td><div id="select_template" style="<?php echo $select_template_style; ?>"><?php echo $html->select('Diagram/template', $templates, array('id'=>'diagram_template')); ?> </div> <span id="use_input_description" style="<?php echo $select_template_style; ?>;"><?php __e('Or you can'); ?> <a href="#" onclick="use_input();return false;"><?php __e('Customize input'); ?></a> </span> <span id="custom_input" style="<?php echo $is_custom_template_style; ?>"><?php echo $html->input('Diagram/custom_template', array('size'=>20)); ?> <?php echo $html->input('Diagram/is_custom_template', array('type'=>'hidden', 'id'=>'is_custom_template')); ?><a href="#" onclick="cancel_custom_input();return false;"><?php __e('Cancel customize'); ?></a></span></td>
      </tr>
      <tr class="finalrow" id="list_type_tr" style="<?php echo $list_type_style; ?>">
        <th><?php __e('List style'); ?></th>
        <td><label><?php echo $html->radio('Diagram/list_type', array('id'=>'list_type_news', 'value'=>'news')); ?> <?php __e('Simple news list'); ?>       <label><?php echo $html->radio('Diagram/list_type', array('id'=>'list_type_images', 'value'=>'images')); ?> <?php __e('Simple images list'); ?></label></td>
      </tr>
      <tr class="finalrow" id="customfields" style="<?php echo $customfields_style; ?>">
        <th><?php __e('Customize field'); ?></th>
        <td>
        <a href="#" onclick="add_custom_row();return false;"><?php __e('+ Add a field');?></a>
<table id="custom_table">
    <tr id="custom_table_fist_tr">
    <th><?php __e('Order'); ?></th><th><?php __e('Name'); ?></th><th><?php __e('Tag'); ?></th><th><?php __e('Action'); ?></th>
    </tr>
<?php
foreach($customfields as $key => $field) {
    echo '<tr id="tr_',$key, '"><td><input type="text" size="5" name="data[Fields][order][]" value="',$field->field_order,'"/></td><td><input type="text" size="20" name="data[Fields][title][]" value="',$field->field_title,'"/></td><td><input type="text" size="20" name="data[Fields][key][]" value="',$field->field_key,'"/></td><td><a href="#" onclick="delete_this_row(',$key,'); return false">', __('Delete') , '</a></td></tr>';
}
?>
</table>

        </td>
      </tr>
    </table>
<div id="page_meta" style="<?php echo $page_content_style; ?>">
<?php require ARLICLE_ELEMENT . 'fckeditor.php'; ?>
</div>

<table>
      <tr class="finalrow">
        <th></th>
        <td align="right">
<input name="publish" id="publish" style="font-weight: bold;" tabindex="5" accesskey="p" value="<?php echo $submit_title; ?>" type="submit">&nbsp;&nbsp;
           </td>
      </tr>
</table>

</div>
    </td>
    <td width="250px" valign="top"></td>
  </tr>
</table>
</div>
</form>
</div>
